#pragma once


namespace SD_Tools
{
	class AbstractIni
	{
	private:

	public:

	private:

	public:
		static bool LoadBool(wchar_t* FilePath, wchar_t* Section, wchar_t* Name, bool* Out);
		static bool LoadInt(wchar_t* FilePath, wchar_t* Section, wchar_t* Name, int* Out);
		static bool LoadHex(wchar_t* FilePath, wchar_t* Section, wchar_t* Name, DWORD* Out);
		static bool LoadFloat(wchar_t* FilePath, wchar_t* Section, wchar_t* Name, float* Out);
		static bool LoadString(wchar_t* FilePath, wchar_t* Section, wchar_t* Name, wchar_t* Out);

		static bool SaveBool(wchar_t* FilePath, wchar_t* Section, wchar_t* Name, bool Value);
		static bool SaveInt(wchar_t* FilePath, wchar_t* Section, wchar_t* Name, int Value);
		static bool SaveHex(wchar_t* FilePath, wchar_t* Section, wchar_t* Name, DWORD Value);
		static bool SaveFloat(wchar_t* FilePath, wchar_t* Section, wchar_t* Name, float Value);
		static bool SaveString(wchar_t* FilePath, wchar_t* Section, wchar_t* Name, wchar_t* String);
	};

	//************************************
	// Method:    LoadBool
	// Profit:	  Loads a bool from an ini file
	// FullName:  SD_Tools::AbstractIni::LoadBool
	// Returns:   bool
	// Notes:
	// -returns false upon failure
	//************************************
	bool AbstractIni::LoadBool( wchar_t* FilePath, wchar_t* Section, wchar_t* Name, bool* Out )
	{
		wchar_t Buffer[256];
		GetPrivateProfileString(Section, Name, L"ERROR", Buffer, sizeof(Buffer), FilePath);
		if (wcscmp(Buffer, L"ERROR") == 0)
		{
			return false;
		}
		else
		{
			*Out = (_wtoi(Buffer) == 1);
			return true;
		}
	}

	//************************************
	// Method:    LoadInt
	// Profit:	  Loads an int from an ini file
	// FullName:  SD_Tools::AbstractIni::LoadInt
	// Returns:   bool
	// Notes:
	// -returns false upon failure
	//************************************
	bool AbstractIni::LoadInt( wchar_t* FilePath, wchar_t* Section, wchar_t* Name, int* Out )
	{
		wchar_t Buffer[256];
		GetPrivateProfileString(Section, Name, L"ERROR", Buffer, sizeof(Buffer), FilePath);
		if (wcscmp(Buffer, L"ERROR") == 0)
		{
			return false;
		}
		else
		{
			*Out = _wtoi(Buffer);
			return true;
		}
	}

	//************************************
	// Method:    LoadHex
	// Profit:	  Loads a Hex from an ini file
	// FullName:  SD_Tools::AbstractIni::LoadHex
	// Returns:   bool
	// Notes:
	// -returns false upon failure
	//************************************
	bool AbstractIni::LoadHex( wchar_t* FilePath, wchar_t* Section, wchar_t* Name, DWORD* Out )
	{
		wchar_t Buffer[256];
		GetPrivateProfileString(Section, Name, L"ERROR", Buffer, sizeof(Buffer), FilePath);
		if (wcscmp(Buffer, L"ERROR") == 0)
		{
			return false;
		}
		else
		{
			*Out = wcstoul(Buffer, NULL, 0);
			return true;
		}
	}

	//************************************
	// Method:    LoadFloat
	// Profit:	  Loads a float from an ini file
	// FullName:  SD_Tools::AbstractIni::LoadFloat
	// Returns:   bool
	// Notes:
	// -returns false upon failure
	//************************************
	bool AbstractIni::LoadFloat( wchar_t* FilePath, wchar_t* Section, wchar_t* Name, float* Out )
	{
		wchar_t Buffer[256];
		GetPrivateProfileString(Section, Name, L"ERROR", Buffer, sizeof(Buffer), FilePath);
		if (wcscmp(Buffer, L"ERROR") == 0)
		{
			return false;
		}
		else
		{
			*Out = (float) _wtof(Buffer);
			return true;
		}
	}

	//************************************
	// Method:    LoadString
	// Profit:	  Loads a wide character string from an ini file
	// FullName:  SD_Tools::AbstractIni::LoadString
	// Returns:   bool
	// Notes:
	// -returns false upon failure
	//************************************
	bool AbstractIni::LoadString( wchar_t* FilePath, wchar_t* Section, wchar_t* Name, wchar_t* Out )
	{
		wchar_t Buffer[256];
		GetPrivateProfileString(Section, Name, L"ERROR", Buffer, sizeof(Buffer), FilePath);
		if (wcscmp(Buffer, L"ERROR") == 0)
		{
			return false;
		}
		else
		{
			wcscpy(Out, Buffer);
			return true;
		}
	}

	//************************************
	// Method:    SaveBool
	// Profit:	  Saves a bool to an ini file
	// FullName:  SD_Tools::AbstractIni::SaveBool
	// Returns:   bool
	// Notes:
	// -returns false upon failure
	//************************************
	bool AbstractIni::SaveBool( wchar_t* FilePath, wchar_t* Section, wchar_t* Name, bool Value )
	{
		wchar_t Buffer[256];
		_itow((int) Value, Buffer, 2);
		return WritePrivateProfileString(Section, Name, Buffer, FilePath) != 0;
	}

	//************************************
	// Method:    SaveInt
	// Profit:	  Saves an int to an ini file
	// FullName:  SD_Tools::AbstractIni::SaveInt
	// Returns:   bool
	// Notes:
	// -returns false upon failure
	//************************************
	bool AbstractIni::SaveInt( wchar_t* FilePath, wchar_t* Section, wchar_t* Name, int Value )
	{
		wchar_t Buffer[256];
		_itow((int) Value, Buffer, 10);
		return WritePrivateProfileString(Section, Name, Buffer, FilePath) != 0;
	}

	//************************************
	// Method:    SaveHex
	// Profit:	  Saves a Hex to an ini file
	// FullName:  SD_Tools::AbstractIni::SaveHex
	// Returns:   bool
	// Notes:
	// -returns false upon failure
	//************************************
	bool AbstractIni::SaveHex( wchar_t* FilePath, wchar_t* Section, wchar_t* Name, DWORD Value )
	{
		wchar_t Buffer[256];
		swprintf(Buffer, L"0x%X", Value);
		return WritePrivateProfileString(Section, Name, Buffer, FilePath) != 0;
	}

	//************************************
	// Method:    SaveFloat
	// Profit:	  Saves a float to an ini file
	// FullName:  SD_Tools::AbstractIni::SaveFloat
	// Returns:   bool
	// Notes:
	// -returns false upon failure
	//************************************
	bool AbstractIni::SaveFloat( wchar_t* FilePath, wchar_t* Section, wchar_t* Name, float Value )
	{
		wchar_t Buffer[256];
		swprintf(Buffer, L"%.02f", Value);
		return WritePrivateProfileString(Section, Name, Buffer, FilePath) != 0;
	}

	//************************************
	// Method:    SaveString
	// Profit:	  Saves a wide character string to an ini file
	// FullName:  SD_Tools::AbstractIni::SaveString
	// Returns:   bool
	// Notes:
	// -returns false upon failure
	//************************************
	bool AbstractIni::SaveString( wchar_t* FilePath, wchar_t* Section, wchar_t* Name, wchar_t* String )
	{
		return WritePrivateProfileString(Section, Name, String, FilePath) != 0;
	}

};